//
//  HomeEmptyView.swift
//  HinsLive
//
//  Created by haoxian on 2019/4/19.
//  Copyright © 2019 Hins. All rights reserved.
//

import UIKit
import RxSwift


class HomeEmptyView: UIView {
    
    private let fakeNavBar: UIView = {
        let v = UIView()
        v.backgroundColor = .standardColor
        return v
    }()
    
    private lazy var emptyView: EmptyView = {
        let v = EmptyView()
        v.didTapSubject.bind(to: didTapSubject).disposed(by: bag)
        return v
    }()
    
    private let bag = DisposeBag()
    
    let didTapSubject = PublishSubject<EmptyView>()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupSubviews()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func showErrorMessage(_ msg: String? = nil) {
        emptyView.showErrorMessage(msg)
    }
}

private extension HomeEmptyView {
    func setupSubviews() {
        addSubview(fakeNavBar)
        fakeNavBar.snp.makeConstraints { (make) in
            make.left.top.right.equalToSuperview()
            make.bottom.equalTo(safeAreaLayoutGuide.snp.top).offset(44)
        }
        
        addSubview(emptyView)
        emptyView.snp.makeConstraints { (make) in
            make.top.equalTo(fakeNavBar.snp.bottom)
            make.left.right.bottom.equalToSuperview()
        }
    }
    
}
